﻿package com.designoutput.manager
{
	public class ResourceManager
	{
		protected static var originalResources:Object = null;
		protected static var resources:Object = null;

		public static function parseResource(resourceString:String):void
		{
			resources = {};
			
			var i:int=0;
			var tmp:Array = null;
			var strArr:Array = resourceString.split("\n");
			var j:int = 0;
			while (j < strArr.length)
			{
				tmp=strArr[j].split("? ");
				if (tmp.length > 1)
				{
					resources[(tmp[0] as String).replace(/^\s+|\s+$/g, "")] = (tmp[1] as String).replace(/^\s+|\s+$/g, "");
					i++;
				}
				j++;
			}
		}

		public static function init():void
		{
			setDefaultResource();
		}

		public static function setDefaultResource():void
		{
			originalResources = {};
			
			originalResources["rm_layout"]= "Layout";
			originalResources["rm_gallery"]= "Gallery";
			originalResources["rm_tools"]= "Tools";
			originalResources["rm_navigator"]= "Navigator";
			
			
			originalResources["rm_ok"]= "OK";
			originalResources["rm_cancel"]= "Cancel";
			originalResources["rm_yes"]= "Yes";
			originalResources["rm_no"]= "No";
			
			originalResources["rm_colorpicker"]= "Color Picker";
			
			originalResources["rm_one_view"]= "1-View";
			originalResources["rm_two_views"]= "2-Views";
			
			
			/***************************************/
			originalResources["rm_front_layer"]= "Front";
			originalResources["rm_back_layer"]= "Back";
			
			originalResources["rm_select"]= "Select";
			originalResources["rm_rectangle"]= "Rectangle";
			originalResources["rm_roundrectangle"]= "Rounded Rectangle";
			originalResources["rm_ellipse"]= "Ellipse";
			
			originalResources["rm_starpolygon"]= "Star/Polygon";
			originalResources["rm_freeformline"]= "Freeform line";
			originalResources["rm_line"]= "Line";
			originalResources["rm_text"]= "Text";
			
			originalResources["rm_image"]= "Image from gallery";
			originalResources["rm_trash"]= "Delete item";
			originalResources["rm_constrain"]= "Constrain proportions";
			originalResources["rm_margins"]= "Show/hide margins frame";
			
			originalResources["rm_ruler"]= "Show/hide ruler";
			originalResources["rm_eraser"]= "Rubber stamps";
			
			
			
			/***************************************/
			originalResources["rm_open"]= "Open Card Log";
			originalResources["rm_save"]= "Save";
			
			originalResources["rm_cut"]= "Cut";
			originalResources["rm_copy"]= "Copy";
			originalResources["rm_paste"]= "Paste";
			
			originalResources["rm_undo"]= "Undo";
			originalResources["rm_redo"]= "Redo";
			
			originalResources["rm_chose_card_color"]= "Click to choose background color";
			
			originalResources["rm_order"]= "Order now";
			originalResources["rm_preview"]= "Preview project";
			
			originalResources["rm_upload_pdf"]= "Upload Pdf file";
			originalResources["rm_upload_psd"]= "Upload psd file";
			originalResources["rm_upload_tif"]= "Upload tif file";
			
			originalResources["rm_help"]= "Click to get help information";
			
			
			/********************************/
			originalResources["rm_portrait"]= "Portrait Orientation";
			originalResources["rm_landscape"]= "Landscape Orientation";
			
			originalResources["rm_short_sleeve_label"]= "Short Sleeve";
			originalResources["rm_long_sleeve_label"]= "Long Sleeve";
			originalResources["rm_left_side_label"]= "Left";
			originalResources["rm_right_side_label"]= "Right";
			
			
			
			/************************options/settings************************************/
			originalResources["rm_base_position_title"]= "Position (left,top)";
			originalResources["rm_base_size_title"]= "Size (width,height)";
			originalResources["rm_base_start_line_title"]= "Start (x1,y1)";
			originalResources["rm_base_end_line_title"]= "End (x2,y2)";
			originalResources["rm_bring_to_front"]= "Bring to front";
			originalResources["rm_bring_forward"]= "Bring forward";
			originalResources["rm_send_backward"]= "Send backward";
			originalResources["rm_send_to_back"]= "Send to back";
			originalResources["rm_radius"]= "Radius:";
			originalResources["rm_star_points"]= "Star Points";
			originalResources["rm_groin_ratio"]= "Groin Ratio";
			originalResources["rm_image_aspect_ratio"]= "Restore Ratio";
			
			originalResources["rm_text_leading"]= "Leading";
			originalResources["rm_text_kerning"]= "Kerning";
			originalResources["rm_line_alpha"]= "Line Alpha";
			originalResources["rm_fill_alpha"]= "Fill Alpha";
			originalResources["rm_font_alpha"]= "Alpha";
			
			/************************Dialogs************************************/
			originalResources["rm_wantToSave_title"] = "Save changes?";
			originalResources["rm_wantToSave_message"] = "Some changes to your layout have not been saved yet.\nWould you like to save now?";
			
			originalResources["rm_overrideCurrentCard"] = "Override current card";
			
			originalResources["rm_service_communication_error"] = "Error while communicating with the service.";
			originalResources["rm_error_message_title"] = "Error";
			
			originalResources["rm_informCardName_title"] = "Inform card name";
			originalResources["rm_informCardName_message"] = "Inform a name for the card.";
		}

		public static function getValue(key:String):String
		{
			if (resources && resources[key] != null)
				return resources[key];

			if (originalResources[key] != null)
				return originalResources[key];

			return key;
		}
	}
}
